package com.heima.canal.entry;

import com.heima.canal.freemarker.ArticlePageHandler;
import com.heima.model.article.pojos.ApArticle;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import top.javatool.canal.client.annotation.CanalTable;
import top.javatool.canal.client.handler.EntryHandler;

/**
 * 此方法用于canal监听ap_article表数据
 */
@Component
@CanalTable(value = "ap_article")
public class ArticleEntry implements EntryHandler<ApArticle> {


    @Autowired
    private ArticlePageHandler articlePageHandler;


    /**
     * 增加，生成静态页
     * <p>
     * 修改：
     * 1）上架，生成静态页
     * 2）下架，删除，删除静态页
     * <p>
     * 删除：删除静态页
     */


    @SneakyThrows
    @Override
    public void insert(ApArticle apArticle) {
        articlePageHandler.article(apArticle);
    }

    @Override
    public void update(ApArticle before, ApArticle after) {
//        if (after.getIsDelete().intValue() != 0 && after.getIsDown() != 0){
//
//            articlePageHandler
//        }
    }

    @Override
    public void delete(ApArticle apArticle) {

    }
}
